package org.fhm.zdte.client.service;

import org.fhm.substrate.annotation.BeanEnable;
import org.fhm.substrate.annotation.Component;
import org.fhm.substrate.annotation.Setup;
import org.fhm.substrate.service.LoggerHandler;
import org.fhm.substrate.standard.ILogger;
import org.fhm.zdte.client.config.ClientInitialConfiguration;
import org.fhm.zdte.common.service.channel.AbstractUDPChannelManager;

/**
 * The UDP-Channel-Manager for the client side.
 *
 * @author 谭波
 * @since 2023/10/14
 */
@Component("DEFAULT")
public class ClientUDPChannelManager extends AbstractUDPChannelManager {

    private final ILogger logger = LoggerHandler.getLogger(ClientUDPChannelManager.class);

    @Setup
    private ClientInitialConfiguration clientInitialConfiguration;

    @Override
    public void initializeChannelManager() {
        openChannel(clientInitialConfiguration.getPort())
                .enableChannel();
        logger.info("enable udp successful");
        setSleepTime();
    }

    @BeanEnable
    private void beanEnable() {
        initializeChannelManager();
    }
}
